//
//  UVCountLabel.m
//  BiuWeather
//
//  Created by 楼楚 on 16/3/4.
//  Copyright © 2016年 Chu Lou. All rights reserved.
//

#import "UVCountLabel.h"
@interface UVCountLabel ()<NumberCountDelegate>

@end


@implementation UVCountLabel



- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.countLabel               = [[UILabel alloc] initWithFrame:self.bounds];
        self.countLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.countLabel];
        self.countLabel.alpha         = 0;
        
        self.uVCount          = [UVCount new];
        self.uVCount.delegate = self;
    }
    
    return self;
}

- (void)numberCount:(NumberCount *)numberCount currentSting:(NSAttributedString *)string {
    
    self.countLabel.attributedText = string;
}

- (void)showDuration:(CGFloat)duration {
    
    self.uVCount.fromValue = self.fromValue;
    self.uVCount.toValue   = self.toValue;
    self.uVCount.duration  = duration;
    self.countLabel.transform    = CGAffineTransformMake(1.5, 0, 0, 1.5, 0, 0);
    
    [self.uVCount startAnimation];
    
    [UIView animateWithDuration:duration animations:^{
        
        self.countLabel.transform = CGAffineTransformMake(1, 0, 0, 1, 0, 0);
        self.countLabel.alpha     = 1.f;
    }];
}

- (void)hideDuration:(CGFloat)duration {
    
    self.uVCount.fromValue = self.toValue;
    self.uVCount.toValue   = 0;
    self.uVCount.duration  = duration;
    
    [self.uVCount startAnimation];
    
    [UIView animateWithDuration:duration animations:^{
        
        self.countLabel.transform = CGAffineTransformMake(0.5, 0, 0, 0.5, 0, 0);
        self.countLabel.alpha     = 0.f;
    }];
}


@end
